<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺名" prop="sName">
        <el-input v-model="queryParams.sName" placeholder="请输入店铺名" clearable @clear="getList"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="服务类型" prop="stName">
        <el-select v-model="queryParams.serviceTypeId" placeholder="请输入服务类型" :style="{width: '100%'}" clearable
          @clear="getList">
          <el-option v-for="item in stList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预约时间">
        <el-date-picker v-model="daterangeReservationTime" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          @change="getList"></el-date-picker>
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态" clearable @clear="getList">
          <el-option v-for="dict in dict.type.status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['business:orders:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ordersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="店铺名" align="center" prop="sname" width="120" />
      <el-table-column label="用户名" align="center" prop="ivName" width="60" />
      <el-table-column label="订单号" align="center" prop="id" width="165" />
      <el-table-column label="服务类型" align="center" prop="stName" width="80" />
      <el-table-column label="服务详情" align="center" prop="sdName" width="180" class="sd" />
      <el-table-column label="核销码" align="center" prop="verificationCode" width="160" />
      <!-- <el-table-column label="核销码图片" align="center" prop="verificationImg" width="100" /> -->
      <el-table-column label="实付价格" align="center" prop="price" width="80" />
      <el-table-column label="预约时间" align="center" prop="reservationTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reservationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="payTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.status" :value="scope.row.status" />
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
  import {
    listOrders,
    getOrders,
    delOrders,
    addOrders,
    updateOrders
  } from "@/api/business/orders";
  import {
    listServiceType
  } from "@/api/business/serviceType";
  import {
    listServiceDetails
  } from "@/api/business/serviceDetails";

  export default {
    name: "Orders",
    dicts: ['status', 'deleted'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 店铺订单管理表格数据
        ordersList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 删除状态时间范围
        daterangeReservationTime: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          verificationCode: null,
          mId: null,
          sName: null,
          uId: null,
          // ivName: null,
          serviceId: null,
          sdName: null,
          serviceTypeId: null,
          stName: null,
          reservationTime: null,
          price: null,
          status: null,
        },
        stList: [], //服务类型
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          id: [{
            required: true,
            message: "订单号不能为空",
            trigger: "blur"
          }],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询店铺订单管理列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};

        // 清空stList
        this.stList = [];

        if (null != this.daterangeReservationTime && '' != this.daterangeReservationTime) {
          this.queryParams.params["beginReservationTime"] = this.daterangeReservationTime[0];
          this.queryParams.params["endReservationTime"] = this.daterangeReservationTime[1];
        }
        listOrders(this.queryParams).then(response => {
          this.ordersList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
        listServiceType(this.queryParams).then(response => {
          var j = response.total;
          for (var k = 0; k < j; k++) {
            var i = response.rows[k];
            if (i.id !== 1 && i.id !== 4) {
              this.stList.push(i);
              // console.log('i', i)
            }
          }
          // console.log('stList:', this.stList)
          this.serviceTypeId = response.rows.id;
          this.loading = false;
          // console.log('stList.response', response)
        });
      },
      // listServiceDetails(this.queryParams).then(response => {
      //              this.sdList = response.rows;
      //              this.loading = false;
      //              console.log('response', response.rows)
      //            });

      // 取消按钮
      // cancel() {
      //   this.open = false;
      //   this.reset();
      // },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          verificationCode: null,
          verificationImg: null,
          mId: null,
          sName: null,
          uId: null,
          // ivName: null,
          serviceId: null,
          sdName: null,
          serviceTypeId: null,
          stName: null,
          orderTime: null,
          reservationTime: null,
          carId: null,
          platformCouponId: null,
          shopCouponId: null,
          price: null,
          payTime: null,
          useTime: null,
          status: null,
          deleted: null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeReservationTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },

      /** 导出按钮操作 */
      handleExport() {
        this.download('business/orders/export', {
          ...this.queryParams
        }, `orders_${new Date().getTime()}.xlsx`)
      }

    }
  };
</script>

<style>
  .sd {
    /* 数据库限制了服务详情 varchar20 */
    /*  word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden; */
  }
</style>
